/***********************************************
 This file is part of redia-bapps-main-ios.
 
 Copyright (c) 2015 Redia A/S
 
 Redia-bapps-main-ios is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 Redia-bapps-main-ios is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with redia-bapps-main-ios.  If not, see <http://www.gnu.org/licenses/>.
 
 *********************************************** */

//
//  BACustomTabBarController.m
//  redia-bapps-ios
//
//  Created by Henrik Lynbech on 14/08/13.
//  Copyright (c) 2013 redia. All rights reserved.
//

#import "BACustomTabBarController.h"
#import "BACustomTabBarBackground.h"

@interface BACustomTabBarController () {
    BACustomTabBarBackground* customBackground;
}

@end

@implementation BACustomTabBarController

-(void)setupViewCustomTabBarController
{
    /*
    UIImageView* tabbarShadow = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.tabBar.frame.origin.y-6, self.tabBar.frame.size.width, 6)]; //Autosizing needs to be set
    [tabbarShadow setImage:[UIImage imageNamed:@"tab-topshadow"]];
    [self.view addSubview:tabbarShadow];
    */
    
    /*
    [self.tabBar setSelectionIndicatorImage:[UIImage imageNamed:@"Tabbar_selection"]];
    */
//    [self.tabBar setSelectedImageTintColor:[UIColor colorWithRed:255.0/255.0 green:80.0/255.0 blue:0.0 alpha:1]];

    [self.tabBar setSelectionIndicatorImage:[UIImage new]]; // Removes the selection overlay on iOS 6
}

- (id)init
{
    self = [super init];
    if (self) {
        [self setupViewCustomTabBarController];
    }
    return self;
}

-(id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self setupViewCustomTabBarController];
    }
    return self;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        [self setupViewCustomTabBarController];
    }
    return self;
}

-(NSUInteger)supportedInterfaceOrientations{
    if (RD_IS_IPAD) {
        return UIInterfaceOrientationMaskLandscape;
    } else{
        return UIInterfaceOrientationMaskPortrait;
    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	
    // Do any additional setup after loading the view.
    //deprecated: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userRequestedLogout) name:BA_DID_REQUEST_LOGOUT object:nil];
}

- (void)dealloc
{
    //deprecated: [[NSNotificationCenter defaultCenter] removeObserver:self name:BA_DID_REQUEST_LOGOUT object:nil];
}

- (void)userRequestedLogout
{
    // Go to the home screen if the user requests logout.
    if ([self.viewControllers count] > 0) {
        [self setSelectedIndex:0];
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)setViewControllers:(NSArray *)viewControllers
{
    if (customBackground!=nil) {
        [customBackground removeFromSuperview];
    }
    
    // Draw a custom background that includes the divider lines.
    customBackground = [[BACustomTabBarBackground alloc] initWithFrame:self.view.bounds items:[viewControllers count]];
    customBackground.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    [customBackground setBackgroundColor:[UIColor colorWithWhite:1 alpha:1]];
    [customBackground setAlpha:1];
    [self.tabBar addSubview:customBackground];
    
    [super setViewControllers:viewControllers];
}



@end
